package com.book.common.utils;


import eu.bitwalker.useragentutils.UserAgent;

import javax.servlet.http.HttpServletRequest;
import java.util.Properties;

/**
 * @Author: Zhang Gaohe
 * @Date: 2021/4/1
 **/
public class BrowserAndOsUtil {
    /**
     * @Author: Mr.ZhangGaohe
     * @Date: 2021/4/1
     * @Description: 第二种方法：通过HttpServletRequest拿到
     */
    public static String getOs() {
        Properties props = System.getProperties();
        return props.getProperty("os.name");
    }

    public static String getBrowser(HttpServletRequest request) {
        UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
        String browserNames = userAgent.getBrowser().toString().toLowerCase();
        String browserName = browserNames.substring(0, 1).toUpperCase() + browserNames.substring(1);
        return browserName;
    }
}
